import "./index.less";
import Notification from "rmc-notification";
let messageInstance = null;
function getMessageInstance(mask, cb) {
  Notification.newInstance(
    {
      style: {
        position: "absolute",
        top: "50%",
        left: "50%",
        transform: "translate(-50%,-50%)",
      },
      className: "m-react-toast",
    },
    (notification) => cb?.(notification)
  );
}

function notice(content, duration) {
  getMessageInstance({}, (notifiction) => {
    if (!notifiction) {
      return;
    }
    if (messageInstance) {
      messageInstance.destroy();
      messageInstance = null;
    }
    messageInstance = notifiction;
    notifiction.notice({
      content,
      duration,
    });
  });
}
export default {
  info(content, duration?) {
    notice(content, duration ? duration : 3);
  },
};
